import json

from django.http import JsonResponse, HttpResponse
from django.shortcuts import render

# Create your views here.
from vehicle.service import VehicleService
from django.core import serializers


def select_vehicle(request):
    user_name = request.POST.get("userName")
    print(user_name)
    return_user = VehicleService().select_vehicle(str(user_name))
    if return_user is not None:
        result_json = serializers.serialize("json", return_user)
        result = {"code": 200, "status": "正确", "data": result_json}
        return HttpResponse(result)
    else:
        result = {"code": 200, "status": "错误", "data": None}
        result = serializers.serialize("json", result)
        return HttpResponse(result)
